---
id: raise-event
title: Raise Event Node
sidebar_label: Raise Event
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

![Raise Event Node Screenshot](./assets/raise-event-node.png)

## Overview

The Raise Event Node allows you to trigger an event from within your graph. This event can be listened for by the host project or by a [Wait For Event Node](./wait-for-event.mdx) within the same graph. This can be useful for triggering actions in your host application based on the state of your graph, or for synchronizing different parts of your graph.

The node requires an event name and optionally an event data. The event name is used to identify the event when it is raised, and the event data is any additional information that you want to associate with the event.

### Toast

In the Rivet application, there is a special event named `toast` which can show a toast message. The `toast` event accepts a string as its data, which is used as the message of the toast.

![Raise Event Node Toast Example](./assets/raise-event-node-toast.png)

<Tabs
  defaultValue="inputs"
  values={[
    {label: 'Inputs', value: 'inputs'},
    {label: 'Outputs', value: 'outputs'},
    {label: 'Editor Settings', value: 'settings'},
  ]
}>

<TabItem value="inputs">

## Inputs

| Title      | Data Type | Description                                                                                        | Default Value | Notes                                                                                      |
| ---------- | --------- | -------------------------------------------------------------------------------------------------- | ------------- | ------------------------------------------------------------------------------------------ |
| Event Name | `string`  | The name of the event to raise. This input is only available if `Use Event Name Input` is enabled. | (required)    | The input will be coerced into a string if it is not a string.                             |
| Data       | `any`     | The data to associate with the event.                                                              | (empty)       | The input will be coerced into the appropriate data type based on the value of the `Data`. |

</TabItem>

<TabItem value="outputs">

## Outputs

| Title  | Data Type | Description                                  | Notes                                                                                    |
| ------ | --------- | -------------------------------------------- | ---------------------------------------------------------------------------------------- |
| Result | `any`     | The data that was associated with the event. | If the `Data` input is not provided, the `Result` output will be an empty string (`""`). |

</TabItem>

<TabItem value="settings">

## Editor Settings

| Setting              | Description                                                               | Default Value | Use Input Toggle | Input Data Type |
| -------------------- | ------------------------------------------------------------------------- | ------------- | ---------------- | --------------- |
| Event Name           | The name of the event to raise.                                           | (required)    | Yes              | `string`        |
| Use Event Name Input | If enabled, the Event Name can be provided via the Event Name input port. | False         | No               | N/A             |

</TabItem>

</Tabs>

## Example 1: Raise an event with data

1. Create a Text Node and set the text to `Hello, world!`.
2. Create a Raise Event Node and leave the Event Name as `toast`.
3. Connect the Text Node to the `Data` input of the Raise Event Node.
4. Run the graph. The `Result` output of the Raise Event Node should be `Hello, world!`, and a toast message should appear in the Rivet application.

![Raise Event Node Example 1](./assets/raise-event-node-toast.png)

## Example 2: Wait for an Chat call to finish before continuing another part of a graph

1. Create a [Chat Node](./chat.mdx) and give it a prompt using a [Text Node](./text.mdx) such as "What is your name?".
2. Create a Raise Event Node, set the Event Name to `chat`, and connect the `Response` output of the Chat Node to the `Data` input of the Raise Event Node.
3. In a separate part of the graph, add a [Wait For Event Node](./wait-for-event.mdx) and set the Event Name to `chat`.
4. Run the graph. Notice that the Wait For Event Node will not continue until the Chat Node has finished.

![Raise Event Node Example 2](./assets/raise-event-node-example-02.png)

## Error Handling

The Raise Event Node will error if the `Event Name` is not provided.

## FAQ

**Q: How can I listen for the event that was raised?**

A: You can listen for the event in your host application by using the `onUserEvent` property of [RunGraphOptions](../api-reference/node/RunGraphOptions). You can also listen for the event within the same graph by using a [Wait For Event Node](./wait-for-event.mdx).

**Q: Can I pass data with the event?**

A: Yes, you can pass data with the event by providing a value to the `Data` input. The data can be of any data type.

**Q: What happens if I raise an event that no one is listening for?**

A: If you raise an event that no one is listening for, nothing will happen. The event will be raised and then immediately discarded.

**Q: How is raising event different from an [External Call Node](./external-call.mdx)?**

A: The External Call Node will wait for the external call to complete before continuing, whereas the Raise Event Node will continue immediately after raising the event.

## See Also

- [Wait For Event Node](./wait-for-event.mdx)
- [External Call Node](./external-call.mdx)
- [RunGraphOptions](../api-reference/node/RunGraphOptions)
